﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using VideoClub.EN.classes;

namespace VideoClub.DS.classes.sp
{
   public class Sp_Del_Handler
    {
        public int delActor(Actor actor, ref string log)
        {
            try
            {
                int rowsaffected = 0;
                using (var conec = new SqlConnection(Properties.Settings.Default.Chesco_PC_Connection_String))
                {
                    SqlCommand cmd = new SqlCommand("Sp_del_actor", conec);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add("@pidactor", SqlDbType.Int).Value = actor.Idactor;
                    conec.Open();
                    rowsaffected = cmd.ExecuteNonQuery();
                    log += rowsaffected;
                    return rowsaffected;
                }
            }
            catch (Exception ex)
            {
                log += ex.Message + ex.StackTrace + ex.Source;
                throw ex;
            }
        }

        public int delAlquiler(Alquiler alquiler, ref string log)
        {
            try
            {
                int rowsaffected = 0;
                using (var conec = new SqlConnection(Properties.Settings.Default.Chesco_PC_Connection_String))
                {

                    SqlCommand cmd = new SqlCommand("Sp_del_alquiler", conec);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add("@pidalquiler", SqlDbType.Int).Value = alquiler.Idalquiler;
                    conec.Open();
                    rowsaffected = cmd.ExecuteNonQuery();
                    log += rowsaffected;
                    return rowsaffected;
                }
            }
            catch (Exception ex)
            {
                log += ex.Message + ex.StackTrace + ex.Source;
                throw ex;
            }
        }

        public int delCategoriaPeli(CategoriaPelicula categoriapelicula, ref string log)
        {
            try
            {
                int rowsaffected = 0;
                using (var conec = new SqlConnection(Properties.Settings.Default.Chesco_PC_Connection_String))
                {
                    SqlCommand cmd = new SqlCommand("Sp_del_categoriapeli", conec);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add("@pidcategoriapeli", SqlDbType.Int).Value = categoriapelicula.Idcategoriapelicula;
                    conec.Open();
                    rowsaffected = cmd.ExecuteNonQuery();
                    log += rowsaffected;
                    return rowsaffected;
                }
            }
            catch (Exception ex)
            {
                log += ex.Message + ex.StackTrace + ex.Source;
                throw ex;
            }
        }

        public int delNacionalidad(Nacionalidad nacionalidad, ref string log)
        {
            try
            {
                int rowsaffected = 0;
                using (var conec = new SqlConnection(Properties.Settings.Default.Chesco_PC_Connection_String))
                {
                    SqlCommand cmd = new SqlCommand("Sp_del_nacionalidad", conec);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add("@pidnacionalidad", SqlDbType.Int).Value = nacionalidad.idnacionalidad;
                    conec.Open();
                    rowsaffected = cmd.ExecuteNonQuery();
                    log += rowsaffected;
                    return rowsaffected;
                }
            }
            catch (Exception ex)
            {
                log += ex.Message + ex.StackTrace + ex.Source;
                throw ex;
            }
        }

        public int delPelicula(Pelicula pelicula, ref string log)
        {
            try
            {
                int rowsaffected = 0;
                using (var conec = new SqlConnection(Properties.Settings.Default.Chesco_PC_Connection_String))
                {
                    SqlCommand cmd = new SqlCommand("Sp_del_pelicula", conec);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add("@pidpelicula", SqlDbType.Int).Value = pelicula.Idpelicula;
                    conec.Open();
                    rowsaffected = cmd.ExecuteNonQuery();
                    log += rowsaffected;
                    return rowsaffected;
                }
            }
            catch (Exception ex)
            {
                log += ex.Message + ex.StackTrace + ex.Source;
                throw ex;
            }
        }

        public int delPeliImgFile(PeliImageFile peliimgfile, ref string log)
        {
            try
            {
                int rowsaffected = 0;
                using (var conec = new SqlConnection(Properties.Settings.Default.Chesco_PC_Connection_String))
                {
                    SqlCommand cmd = new SqlCommand("Sp_del_peliimgfile", conec);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add("@pidpelicula", SqlDbType.Int).Value = peliimgfile.Idpelicula;
                    conec.Open();
                    rowsaffected = cmd.ExecuteNonQuery();
                    log += rowsaffected;
                    return rowsaffected;
                }
            }
            catch (Exception ex)
            {
                log += ex.Message + ex.StackTrace + ex.Source;
                throw ex;
            }
        }

        public int delSolicitud(Solicitud solicitud, ref string log)
        {
            try
            {
                int rowsaffected = 0;
                using (var conec = new SqlConnection(Properties.Settings.Default.Chesco_PC_Connection_String))
                {
                    SqlCommand cmd = new SqlCommand("Sp_del_solicitud", conec);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add("@pidsolicitud", SqlDbType.Int).Value = solicitud.Idsolicitud;
                    conec.Open();
                    rowsaffected = cmd.ExecuteNonQuery();
                    log += rowsaffected;
                    return rowsaffected;
                }
            }
            catch (Exception ex)
            {
                log += ex.Message + ex.StackTrace + ex.Source;
                throw ex;
            }
        }

        public int delTipoUsuario(TipoUsuario tipousuario, ref string log)
        {
            try
            {
                int rowsaffected = 0;
                using (var conec = new SqlConnection(Properties.Settings.Default.Chesco_PC_Connection_String))
                {
                    SqlCommand cmd = new SqlCommand("Sp_del_tipousuario", conec);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add("@pidtipousuario", SqlDbType.Int).Value = tipousuario.Tipousuario;
                    conec.Open();
                    rowsaffected = cmd.ExecuteNonQuery();
                    log += rowsaffected;
                    return rowsaffected;
                }
            }
            catch (Exception ex)
            {
                log += ex.Message + ex.StackTrace + ex.Source;
                throw ex;
            }
        }

        public int delUsuario(Usuario usuario, ref string log)
        {
            try
            {
                int rowsaffected = 0;
                using (var conec = new SqlConnection(Properties.Settings.Default.Chesco_PC_Connection_String))
                {
                    SqlCommand cmd = new SqlCommand("Sp_del_usuario", conec);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add("@pidusuario", SqlDbType.Int).Value = usuario.Idusuario;
                    conec.Open();
                    rowsaffected = cmd.ExecuteNonQuery();
                    log += rowsaffected;
                    return rowsaffected;
                }
            }
            catch (Exception ex)
            {
                log += ex.Message + ex.StackTrace + ex.Source;
                throw ex;
            }
        }

        public int delVideoPelicula(VideoPelicula videopelicula, ref string log)
        {
            try
            {
                int rowsaffected = 0;
                using (var conec = new SqlConnection(Properties.Settings.Default.Chesco_PC_Connection_String))
                {
                    SqlCommand cmd = new SqlCommand("Sp_del_videopelicula", conec);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add("@pidvideopelicula", SqlDbType.Int).Value = videopelicula.Idpelicula;
                    conec.Open();
                    rowsaffected = cmd.ExecuteNonQuery();
                    log += rowsaffected;
                    return rowsaffected;
                }
            }
            catch (Exception ex)
            {
                log += ex.Message + ex.StackTrace + ex.Source;
                throw ex;
            }
        }
    }
}

